package com.deer.wms.ware.task.web;

import com.deer.wms.ware.task.model.Sale.SaleDetail;
import com.deer.wms.ware.task.model.Sale.SaleDetailCriteria;
import com.deer.wms.ware.task.service.SaleDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/03/13.
*/
@Api(description = "销售信息api接口")
@RestController
@RequestMapping("/sale/details")
public class SaleDetailController {

    @Autowired
    private SaleDetailService saleDetailService;

    @PostMapping("/insert")
    public Result insert(@RequestBody SaleDetail saleDetail) {
        saleDetailService.save(saleDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        saleDetailService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody SaleDetail saleDetail) {
        saleDetailService.updateById(saleDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        SaleDetail saleDetail = saleDetailService.getById(id);
        return ResultGenerator.genSuccessResult(saleDetail);
    }

    @GetMapping("/list")
    public Result list(SaleDetailCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SaleDetail> list = saleDetailService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
